{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Processing Clock\n", "\n", "This is running the Calysto Processing kernel. The published (nbviewer) notebook actually contains the running code." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_1\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_1\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_1\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_1\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #1:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #1 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "int cx, cy;\n", "float secondsRadius;\n", "float minutesRadius;\n", "float hoursRadius;\n", "float clockDiameter;\n", "\n", "void setup() {\n", " size(640, 360);\n", " stroke(255);\n", " \n", " int radius = min(width, height) / 2;\n", " secondsRadius = radius * 0.72;\n", " minutesRadius = radius * 0.60;\n", " hoursRadius = radius * 0.50;\n", " clockDiameter = radius * 1.8;\n", " \n", " cx = width / 2;\n", " cy = height / 2;\n", "}\n", "\n", "void draw() {\n", " background(0);\n", " \n", " // Draw the clock background\n", " fill(80);\n", " noStroke();\n", " ellipse(cx, cy, clockDiameter, clockDiameter);\n", " \n", " // Angles for sin() and cos() start at 3 o'clock;\n", " // subtract HALF_PI to make them start at the top\n", " float s = map(second(), 0, 60, 0, TWO_PI) - HALF_PI;\n", " float m = map(minute() + norm(second(), 0, 60), 0, 60, 0, TWO_PI) - HALF_PI; \n", " float h = map(hour() + norm(minute(), 0, 60), 0, 24, 0, TWO_PI * 2) - HALF_PI;\n", " \n", " // Draw the hands of the clock\n", " stroke(255);\n", " strokeWeight(1);\n", " line(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);\n", " strokeWeight(2);\n", " line(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);\n", " strokeWeight(4);\n", " line(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);\n", " \n", " // Draw the minute ticks\n", " strokeWeight(2);\n", " beginShape(POINTS);\n", " for (int a = 0; a < 360; a+=6) {\n", " float angle = radians(a);\n", " float x = cx + cos(angle) * secondsRadius;\n", " float y = cy + sin(angle) * secondsRadius;\n", " vertex(x, y);\n", " }\n", " endShape();\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Calysto Processing", "language": "java", "name": "calysto_processing" }, "language_info": { "codemirror_mode": { "name": "text/x-java", "version": 2 }, "file_extension": ".java", "mimetype": "text/x-java", "name": "java" } }, "nbformat": 4, "nbformat_minor": 0 }